package com.andaily.domain.thing;

import com.andaily.domain.shared.Repository;
import com.andaily.domain.user.ThingSetting;
import com.andaily.domain.user.User;
import com.andaily.infrastructure.mybatis.data.ThingStatisticsData;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author Shengzhao Li
 */
public interface ThingRepository extends Repository {

    Thing findByGuid(String guid);

    Event findEventByGuid(String guid);

    void saveThing(Thing thing);

    void saveEvent(Event event);

    void updateEvent(Event event);

    List<Event> findAvailableEvents(String userGuid);

    void updateThing(Thing thing);

    int totalThings();

    List<Event> findEvents(Map<String, Object> params);

    int totalEvents(Map<String, Object> params);

    int amountThingsByStatus(@Param("userGuid") String userGuid, @Param("statuses") ThingStatus... statuses);

    int amountOfWarning(@Param("userGuid") String userGuid, @Param("now") Date now, @Param("status") ThingStatus status);

    void archiveEvent(@Param("guid") String guid, @Param("archive") boolean archive);

    List<Thing> findThings(Map<String, Object> params);

    int amountOfThings(Map<String, Object> params);

    int countThingsOfPriorities(@Param("userGuid") String userGuid, @Param("priorities") ThingPriority... priorities);

    void updateThingStatus(@Param("guid") String guid, @Param("status") ThingStatus status);

    void updateThingCancelTime(@Param("guid") String guid, @Param("cancelTime") Date cancelTime);

    void updateThingEndTime(@Param("guid") String guid, @Param("endTime") Date endTime);

    int totalWarningThings(Map<String, Object> params);

    List<Thing> findWarningThings(Map<String, Object> params);

    void archiveThings(@Param("guids") String[] guids, @Param("archive") boolean archive);

    List<Thing> findSearchThings(Map<String, Object> params);

    int totalSearchThings(Map<String, Object> params);

    void updateThingSetting(@Param("thingSetting") ThingSetting thingSetting, @Param("userGuid") String userGuid);

    ThingStatus findDefaultStatus(String userGuid);

    List<ThingStatisticsData> findStatusStatisticsDatas(String userGuid);

    List<ThingStatisticsData> findPriorityStatisticsDatas(String userGuid);

    List<Thing> findStartTimeThings(@Param("user") User user, @Param("startDate") java.sql.Date startDate);

    void updateThingsStatus(@Param("things") List<Thing> things, @Param("status") ThingStatus status);

    void updateThingsAutoPendingByScheduler(@Param("things") List<Thing> availableThings, @Param("autoPendingByScheduler") boolean autoPendingByScheduler);
}
